<?php
namespace App\Models;

class HdMtReceiptLog extends Base {

    public function initialize() {
        parent::initialize();
    }

    public function getSource() {
        return 'hd_mt_receipt_log';
    }

    /**
     * 插入数据
     *
     * @param array $data
     *
     * @return false|int
     */
    public function add($data) {
        try {
            if($this->db()->insertAsDict($this->getSource(), $data) !== false) {
                $receiptLog = [
                    'mobile'      => $data['mobile'],
                    'status'      => $data['status'] == 'DELIVRD' ? 1 : 0,
                    'gateway'     => 'hd',
                    'gateway_msg' => urldecode(http_build_query($data)),
                    'receive_at'  => $data['receive_at'],
                    'create_at'   => date('Y-m-d H:i:s')
                ];
                $this->db()->insertAsDict('sms_receipt_log', $receiptLog);
                //return $this->db()->lastInsertId();
                return true;
            }
        } catch(\PDOException $ex) {
            $this->errorLog('INSERT', $this->db()->getSQLStatement(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }
}
